package com.wrt.wm.service.impl;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.wrt.wm.service.ParametersService;

import net.coobird.thumbnailator.geometry.Positions;

@Service
public class ParametersServiceImpl implements ParametersService {
	
	private List<String> systemFonts = new ArrayList<>();

	@Override
	public List<String> getSystemFontList() {
		return this.systemFonts;
	}

	@Override
	public void refreshFontList() {
		initSystemFonts();
	}


	@Override
	public String[] getImgPositions() {
		String [] positionname = new String [Positions.values().length];
		for(Positions p: Positions.values()) {
			positionname[p.ordinal()] = p.name();
		}
		return positionname;
	}
	
	/**
	 * 初始化当前系统内的字体
	 */
	@PostConstruct
	private void initSystemFonts() {
		GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
		Font[] fonts = e.getAllFonts();
		Set<String> temp = new HashSet<>();
		for (Font font : fonts) {
			temp.add(font.getFontName());
		}
		systemFonts.clear();
		systemFonts.addAll(temp.stream().collect(Collectors.toList()));
	}
}
